<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
    一般用catch捕获失败
    当调用catch方法的promise实列是失败状态的 则会执行catch中的回调函数
    catch的作用和then方法的第二个回调函数的作用一致
    所有catch的返回值和then方法的返回值保持一致
    */
    const p1 = new Promise((resolve, reject) => {
      throw new Error('错误')
      try {
        console.log('获取数据A');
        
        setTimeout(() => {
          console.log('A数据成功');
          resolve('1')
        }, 2000)
      } catch (e) {
        console.log(e.message);
      }
    })

    p1.then((v) => {
      console.log(v);
    })

    const p2 = p1.catch((reason) => {
      throw new Error('错误')
    })

    console.log('p1', p1);
    console.log('p2', p2);
  </script>
</body>

</html>